/*
 * @Author: yupi
 * @Date: 2019-11-30
 * @Description: 通用的service
 */
import Taro from "@tarojs/taro";

const db = Taro.cloud.database();

/**
 * 根据id获取用户信息
 * @param userId
 */
export function getUserById(userId) {
  return db.collection('user')
    .where({
      _id: userId,
    })
    .limit(1)
    .get()
    .then(({data}) => {
      if (data.length > 0) {
        return data[0];
      }
      return null;
    });
}
/**
 * @description: 通过班级密钥获得班级
 * @author: YUWENJING
 * @date: 2020/2/15
 * @param classKey
 */


export  function getClassByClassKey(classKey) {

   return  db.collection('class')
    .where({
      classKey
    })
    .get()
    .then(res => {
     return  res.data[0]
    })


}

